package huoye.shops.huoye.mine.adapter;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.codeideology.android.widget.recycler.RecyclerViewAdapter;

import butterknife.BindView;
import huoye.shops.R;
import huoye.shops.base.APIUrls;
import huoye.shops.huoye.mine.model.AccountList;
import huoye.shops.huoye.operation.model.ManageEventData;
import huoye.shops.huoye.user.model.User;
import huoye.shops.widget.RoundImageView;


/**
 * Created by uesr on 2018/8/10.
 */

public class ManageAccountAdapter extends RecyclerViewAdapter<ManageAccountAdapter.ViewHolder,AccountList> {


    public ManageAccountAdapter(Context context) {
        super(context, R.layout.item_manage_account);
    }

    @Override
    protected ViewHolder initViewHolder(View view, int i) {

        return new ViewHolder(view);
    }

    @Override
    protected void bindView(ViewHolder holder, final AccountList accountList, int i) {


        holder.tvName.setText(accountList.getUserName());
        if(getContext() != null){
            Glide.with(getContext())
                    .load(accountList.getWxHeadImg())
                    .dontAnimate()
                    .placeholder(R.mipmap.ic_wait_logo)
                    .error(R.mipmap.ic_error)
                    .into(holder.rvHead);
        }

        if(accountList.getiState() == 1){
            holder.tvStare.setSelected(false);
            holder.tvStare.setText("正常");
        }else {
            holder.tvStare.setSelected(true);
            holder.tvStare.setText("禁用");
        }

        holder.tvAccount.setText("账户"+accountList.getMobile());

        holder.btnDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onDeleteClick(accountList);
            }
        });
        holder.btnEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onEditClick(accountList);
            }
        });

    }


    public class ViewHolder extends RecyclerViewAdapter.ViewHolder {

        @BindView(R.id.item_manage_account_tv_name)
        TextView tvName;
        @BindView(R.id.item_manage_account_tv_state)
        TextView tvStare;
        @BindView(R.id.item_manage_account_tv_account)
        TextView tvAccount;



        @BindView(R.id.item_manage_account_rv_head)
        RoundImageView rvHead ;


        @BindView(R.id.item_manage_account_btn_delete)
        Button btnDelete ;
        @BindView(R.id.item_manage_account_btn_edit)
        Button btnEdit;
  ;


        public ViewHolder(View itemView) {
            super(itemView);
        }
    }



    public void setOnManageAccountDataListener(OnManageAccountListener onManageAccountListener) {
        this.listener = onManageAccountListener;
    }

    private OnManageAccountListener listener;

    public interface OnManageAccountListener {

        void onDeleteClick(AccountList accountList);
        void onEditClick(AccountList accountList);


    }

}
